package com.jet.chat.message;

import java.util.ArrayList;


public class MessageQueue {
	ArrayList<Message> queue = new ArrayList<Message>();

	public ArrayList<Message> getQueue() {
		return this.queue;
	}

	public synchronized void addMessage(Message message) {
		this.queue.add(message);
		notifyAll();
	}

	public synchronized void addMessage(String string) {
		this.queue.add(new Message(string));
		notifyAll();
	}

	public synchronized Message getMessage() throws InterruptedException {
		while (this.queue.isEmpty()) {
			wait();
		}
		
		return this.queue.remove(0);
	}
}
